package com.ws.webServiceConfig;

import com.ws.service.DemoService;
import com.ws.service.YthService;
import com.ws.service.impl.DemoServiceImpl;
import com.ws.service.impl.YthServiceImpl;
import org.apache.cxf.Bus;
import org.apache.cxf.bus.spring.SpringBus;
import org.apache.cxf.jaxws.EndpointImpl;
import org.apache.cxf.transport.servlet.CXFServlet;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.ws.transport.http.MessageDispatcherServlet;

import javax.xml.ws.Endpoint;

/**
 * @ClassName CxfConfig
 * @Description TODO
 * @Author zhengchenggong
 * @Date 2020/7/14 1:59 下午
 * @Version 1.0
 **/

@Configuration
public class CxfConfig {

    @Autowired
    YthService ythService;

    public CxfConfig(){
        System.out.println("CxfConfig进来了...");
    }

    @Bean
    public ServletRegistrationBean adispatcherServlet() {
        return new ServletRegistrationBean(new CXFServlet(), "/apis/*");
    }

    @Bean(name = Bus.DEFAULT_BUS_ID)
    public SpringBus springBus() {
        return new SpringBus();
    }

//    @Bean
//    public DemoService demoService() {
//        return new DemoServiceImpl();
//    }
    /*public YthService demoService() {
        return new YthServiceImpl();
    }*/

    @Bean
    public Endpoint endpoint() {
        EndpointImpl endpoint = new EndpointImpl(springBus(), ythService);
        endpoint.publish("/api");
        return endpoint;
    }

}
